    var $;
    var layer;
    var table;
    var form;
    layui.use(['layer', 'table', 'form'], function () {
        layer = layui.layer;
        $ = layui.jquery;
        table = layui.table;
        form = layui.form;
        getTab();
        getcomment();//评论区初始化
        //获取当前登陆人员的信息
        var create=localStorage.getItem("user");
        create=JSON.parse(create);//将获取json字符串转json对象
        $("#sendUserName").val(create.true_name);
        $("#sendUserAccount").val(create.account);
 });
 //初始化表格
 function getTab() {
     var id=$("#courseId").val();
     var type=$("#type").val();

     if(type==3){
         $.ajax({
             url:"/SyOperationController/selCourseInfo",
             type:"post",
             dataType:"json",
             data:{"courseId":id},
             success:function(data){

                 for(var a=0;a<data.data.microcircleImg.length;a++){
                     $(".td4").append("<img src='"+ data.data.microcircleImg[a].picture_url+"'class='microcircleImg'>");
                 }
                 if(data.code>-1){
                     $("#courseName").val(data.data.courseName);//课程名称

                     var createDate=data.data.createDate
                     createDate = createDate.slice(0, createDate.indexOf("."));
                     createDate = createDate.replaceAll('T',' ');


                     $("#createDate").val(createDate);//上传时间
                     var obj = data.data;
                     if(obj.type==2){
                         var tableName = 'sy_before_user';
                         var tableInfo = 'nickname';
                         var userId = data.data.userId;
                         selUserInfos(tableName,tableInfo,userId);
                     }else if(obj.type==3){
                         var tableName = 'sy_user';
                         var tableInfo = 'true_name';
                         var userId =  data.data.userId;
                         selUserInfos(tableName,tableInfo,userId);
                     }
                     $("#courseNprice").val(data.data.courseNprice);//课程售价
                     $("#coursePrimary").val(data.data.coursePrimary);//课程关键字
                     $("#courseCatory").val(data.data.className);//课程分类
                     $("#likeNum").val(data.data.likeNum);//点赞量
                     $("#collectNum").val(data.data.collectNum);//收藏量
                     $("#commentNum").val(data.data.commentNum);//评论量
                     $("#courseIntro").val(data.data.courseIntro);//课程介绍

                     $("#img").attr("src",data.data.url);//课程封面图url

                     var ht="<source src='"+data.data.courseUrl+"' type='video/mp4' id='sourcId'/>"
                     $("#videId").html(ht)
                 }
             },
             error: function () {
                 layer.msg('数据出错！');
             }
         });
     }else if(type==2){
         $.ajax({
             url:"/SyOperationController/selBeforeCourse",
             type:"post",
             dataType:"json",
             data:{"courseId":id},
             success:function(data){
                 if(data.code>-1){
                     $("#courseName").val(data.data.courseName);//课程名称
                     var createDate=settime(data.data.createDate);
                     $("#createDate").val(createDate);//上传时间
                     var obj = data.data;
                     if(obj.type==2){
                         var tableName = 'sy_before_user';
                         var tableInfo = 'nickname';
                         var userId = data.data.userId;
                         selUserInfos(tableName,tableInfo,userId);
                     }else if(obj.type==3){
                         var tableName = 'sy_user';
                         var tableInfo = 'true_name';
                         var userId =  data.data.userId;
                         selUserInfos(tableName,tableInfo,userId);
                     }
                     $("#courseNprice").val(data.data.courseNprice);//课程售价
                     $("#coursePrimary").val(data.data.coursePrimary);//课程关键字
                     $("#courseCatory").val(data.data.className);//课程分类
                     $("#likeNum").val(data.data.likeNum);//点赞量
                     $("#collectNum").val(data.data.collectNum);//收藏量
                     $("#commentNum").val(data.data.commentNum);//评论量
                     $("#courseIntro").val(data.data.courseIntro);//课程介绍
                     $("#img").attr("src",data.data.url);//课程封面图url
                     var ht="<source src='"+data.data.courseUrl+"' type='video/mp4' id='sourcId'/>"
                     $("#videId").html(ht)
                 }
             },
             error: function () {
                 layer.msg('数据出错！');
             }
         });
     }
 };
    //获取人员信息
    function selUserInfos(tableName,tableInfo,userId){
        $.post('/SyOperationController/seluserInfos',{"tableName":tableName,"tableInfo":tableInfo,"userId":userId},function(res){
            $('input[name=createName]').val(res.data.userNames);
            $('input[name=userId]').val(res.data.userId);
        })
    }
 /*日期转换*/
    function settime(da){
        var date=new Date(da);
        var year=date.getFullYear();
        var month=date.getMonth()+1;
        var day=date.getDate();
        var hours=date.getHours();
        var mm=date.getMinutes();
        var s=date.getSeconds();
        return year+'-'+add(month)+'-'+add(day)+' '+add(hours)+':'+add(mm)+':'+add(s);
        //return year+'-'+month+'-'+day+' '+hours+':'+mm+':'+s;
    };
    function add(time){//给非整数添0
        return time<10?'0'+time:time;
    };
    var liminum=0;
    //评论区
    function getcomment() {
        var id=$("#courseId").val();
        var com="";
        var type=2;
        $.post("/SyOperationController/selCommentInfo", {"id":id,"type":type}, function (res) {
            if (res.code>-1) {
                if(res.data.length!=0){
                    liminum=res.data.length;
                    for(var i=0;i<res.data.length;i++){
                        if(res.data[i].userImg!=null){
                            com+="<li class='ulli'><div class='lidiv'>" +
                                "<div class='lidiv1'><div class='liImgdiv'><img class='UserImg' src='"+res.data[i].userImg+"'/></div></div>" +
                                "<div class='licondiv'><p class='userNane'>"+res.data[i].userName+"</p>" +
                                "<p class='comp'>"+res.data[i].content+"</p>" +
                                "<p class='actp'>"+settime(res.data[i].commentDate)+ "" +
                                "<span class='pspupd' onclick='updComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>隐藏</span>" +
                                "<span class='pspdel' onclick='delComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>删除</span></p></div>" +
                                "<input class='comid' value='"+res.data[i].id+"' type='hidden' name='comid'></div></li>";
                        }else {
                            com+="<li class='ulli'><div class='lidiv'>" +
                                "<div class='lidiv1'><div class='liImgdiv'><i class='layui-icon' class='li_i'>&#xe612;</i></div></div>" +
                                "<div class='licondiv'><p class='userNane'>"+res.data[i].userName+"</p>" +
                                "<p class='comp'>"+res.data[i].content+"</p>" +
                                "<p class='actp'>"+settime(res.data[i].commentDate)+
                                "<span class='pspupd' onclick='updComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>隐藏</span>" +
                                "<span class='pspdel' onclick='delComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>删除</span></p></div>" +
                                "<input class='comid' value='"+res.data[i].id+"' type='hidden' name='comid'></div></li>";
                        }
                    }
                    $("#commentUl").html(com);
                    $('#nocomDiv').css("display","block");
                }else{
                    $('#nocomDiv').css("display","block");
                }
            } else {
                $('#nocomDiv').css("display","block");
            }
        });
    }
    //评论状态修改
    function updComment(id,content) {
        var status=2;
            layer.confirm("您确定要拦截`"+content+"`评论吗?",function (rel) {
                $.ajax({
                    url: "/SyOperationController/updComment",
                    type: "post",
                    dataType: "json",
                    data:{"id":id,"status":status},
                    success: function (data) {
                        if(data.code==0){
                            layer.msg("拦截成功",{icon:1});
                            getcomment();
                        }else{
                            layer.msg("拦截失败",{icon:2});
                            getcomment();
                        }
                    }
                });
            },function (res) {
            });
    }
    //评论状态修改为删除
    function delComment(id,content) {
        layer.confirm("您确定要删除`"+content+"`评论吗?",function (rel) {
            $.ajax({
                url: "/SyOperationController/updComment",
                type: "post",
                dataType: "json",
                data:{"id":id,"status":3},
                success: function (data) {
                    if(data.code==0){
                        layer.msg("删除成功",{icon:1});
                        getcomment();
                    }else{
                        layer.msg("删除失败",{icon:2});
                        getcomment();
                    }
                }
            });
        },function (res) {
        });
    }
    //评论视频
    function addCommentInfo(){
        var vals = "";
        var content = $("#textsId").val();
        if(!content){
            layer.msg("内容不能为空",{icon:5});
        }else{
            var create=localStorage.getItem("user");
            create=JSON.parse(create);//将获取json字符串转json对象
            var userId = create.user_id;
            var commodityId=$("#courseId").val();
            vals+="&userId="+userId;
            vals+="&commodityId="+commodityId;
            vals+="&content="+content;
            vals+="&type="+2;
            $.post("/SyOperationController/addCommentInfo", vals, function (res) {
                if(res.code>-1){
                    layer.msg("评论成功",{icon:1});
                    getcomment();
                    $("#textsId").val('');
                }else{
                    layer.msg("评论失败",{icon:2});
                    getcomment();
                }
            });
        }
    }